import {createConnection} from "typeorm";
import Admin from '../src/entity/admin'

createConnection({
    "type": "mysql",
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "gao",
    "database": "g_blog",
    "synchronize": true,
    "logging": true,
    "entities": [
        Admin,
    ],
    "migrations": [
       "src/migration/**/*.ts"
    ],
    "subscribers": [
       "src/subscriber/**/*.ts"
    ]
}).then(async connection=>{
    console.log('inserting into the user table')
    let admin = new Admin()
    admin.username = 'dddde'
    admin.g_password = '22dddddd2'
    admin.g_uuid = 'd33333333333333'
    admin.gmt_created = new Date().toUTCString()
    admin.gmt_updated = admin.gmt_created
    let userReop = connection.getRepository(Admin)
    try{
        await userReop.save(admin)
        console.log('success !')
    }catch(e){
        console.error('failure !')
        throw(e)
    }

}).catch(err=>{
    console.log(err)
})